﻿Imports Clases.Imagen
Public Class frmPrincipal

    Private Sub CargarImagenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CargarImagenToolStripMenuItem.Click
        CrearFormulario()

    End Sub

    Private Sub CrearFormulario()
        Dim explorar As New OpenFileDialog()
        explorar.InitialDirectory = "c:\"
        explorar.Filter = "gif files (*.gif)|*.gif| all (*.*)|*.*"
        explorar.FilterIndex = 2
        'explorar.RestoreDirectory = True

        If explorar.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            Try
                For i = 1 To My.Application.OpenForms.Count - 1
                    If My.Application.OpenForms(i).Text = explorar.FileName Then
                        MessageBox.Show("La imagen ya existe")
                        Exit Sub
                    End If
                Next
                Dim frmNuevo As New Form
                Dim pictureForm As New PictureBox


                cont += 1

                frmNuevo.Size = New Size(500, 500)
                pictureForm.Size = New Size(50, 50)
                frmNuevo.Text = "frm" & cont
                pictureForm.Visible = True
                pictureForm.Enabled = True
                pictureForm.Location = New Point(225, 225)
                pictureForm.BackColor = Color.Aqua
                frmNuevo.Controls.Add(pictureForm)
                frmNuevo.Show()

                miImagen = New Clases.Imagen
                Dim str As String = explorar.FileName
                miImagen.CargarDatosImagen(str)



                AddHandler pictureForm.MouseHover, AddressOf pictureForm_MouseHover

                AddHandler pictureForm.MouseLeave, AddressOf pictureForm_MouseLeave


                'miImagen.RutaCompleta = str
                pictureForm.Image = miImagen.Imagen
                pictureForm.SizeMode = PictureBoxSizeMode.StretchImage
                'pictureForm.Width = pictureForm.Image.Width
                'pictureForm.Height = pictureForm.Image.Height
                frmNuevo.Text = str
                frmNuevo.Name = "frmSecundario"
                'My.Computer.Audio.Play("C:\Users\Public\Music\Sample Music\Kalimba2.wav",
                'AudioPlayMode.WaitToComplete)
            Catch e As Exception
            End Try
        End If
    End Sub
    Private Sub pictureForm_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover
        TryCast(sender, PictureBox).Dock = DockStyle.Fill
        'TryCast(sender, PictureBox).BackgroundImageLayout = ImageLayout.Stretch

    End Sub
    Private Sub pictureForm_MouseLeave(ByVal sender As Object, ByVal system As EventArgs) Handles PictureBox1.MouseLeave
        TryCast(sender, PictureBox).Dock = DockStyle.None
        'TryCast(sender, PictureBox).Anchor =
        TryCast(sender, PictureBox).Width = TryCast(sender, PictureBox).Width
        TryCast(sender, PictureBox).Height = TryCast(sender, PictureBox).Height

    End Sub

    Private Sub DescargarImagenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DescargarImagenToolStripMenuItem.Click
        Dim cont As Integer = My.Application.OpenForms.Count - 1
        Do
            For i = 0 To cont
                If My.Application.OpenForms(i).Name = "frmSecundario" Then
                    cont = cont - 1
                    My.Application.OpenForms(i).Close()
                    Exit For
                End If
            Next
        Loop Until My.Application.OpenForms.Count = 1
    End Sub

    Private Sub SalirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalirToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub AcercaDeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AcercaDeToolStripMenuItem.Click
        AboutBox1.Show()
    End Sub


    Private Sub frmPrincipal_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Form1.Show()
    End Sub
End Class